/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.pz.net;

import java.nio.ByteBuffer;

/**
 *
 * @author Jannek
 */
public class Message {

    private static Message idle = null;
    
    public ByteBuffer data;
    
    protected Message next;
    
    protected short id;
    protected short required;

    public static Message get() {
        Message message;

        if (idle != null) {
            message = idle;
            idle = idle.next;
            message.reset();
        } else {
            message = new Message();
        }

        return message;
    }

    private Message() {
        data = ByteBuffer.allocate(497);
        reset();
    }

    private void reset() {
        data.clear();
        next = null;
    }
    
    public void dispose()
    {
        next = idle;
        idle = this;
    }
    
    public void finalize(short requiredId, short packageId)
    {
        id = packageId;
        required = requiredId;
        data.flip();
    }
}
